package cn.lijiajia3515.cairo.system.modules.area;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public interface AreaInterface {
	String PREFIX = "/api/area";

	@PostMapping(PREFIX + "/find")
	List<Area> find(@RequestBody FindAreaParam param);

	default Map<String, Area> findMap(FindAreaParam param) {
		return param.getIds().isEmpty() ? Collections.emptyMap() : find(param).stream().collect(Collectors.toMap(Area::getId, x -> x));
	}

	@GetMapping(PREFIX + "/find_id/{id}")
	Optional<Area> findById(@PathVariable(name = "id") String id);

	@GetMapping(PREFIX + "/find_subs/{id}")
	List<AreaTree> find(@PathVariable(name = "id") String id);
}
